/**
* @Title: caseAuditList_Ctrl.js
* @Description: TODO
* Copyright: Copyright (c) 2014 
 * Company:中国平安
*
* @Project HIMS-FWA
* @date 2014年10月27日 下午4:43:38
* @version V1.0
*/
;
(function(){
	'use strict';
	
	var app = angular.module('fwa.mainApp');
	app.controller('ProblemSearchListCtrl', ['$scope','$state','$http','$modal','CaseAuditListService','CaseCommonService',
	                                           'BaseURL','Modal','FwaTabsetService','AuditDictServices','InsuranceService',
	                                function($scope,$state,$http,$modal,caseAuditListService,CaseCommonService,
	                                		baseUrl,Modal,fwaTabsetService,AuditDictServices,InsuranceService){
		$scope.addOnClick = function(){
			fwaTabsetService.selectTab('problemRegister.addProblemInfo',null,false);
		}
		
		InsuranceService.initMedicalOrgInfoList().success(function(response){
            $scope.medicalOrgInfoList = response.medicalOrgList;
		});
		$scope.auditDictServices = AuditDictServices;
		AuditDictServices.initCodeListDatas();
		
		$scope.columns = [
  		{
			label : '事件号',
			map : 'problemCode',
			width : '10%',
			 cellTemplate:'<a  ng:bind="data.problemCode" '+
			 	'ng-click="operation(data)"></a>'}, 
		{
			label : '事件时间段',
			map : 'periodDate',
			width : '15%'
		}, {
			label : '事件要点',
			map : 'keyPoint',
			width : '20%'
		}, {
			label : '来源方式',
			map : 'sourceType',
			width : '10%'
		}, {
			label : '提交日期',
			map : 'submitDate',
			width : '15%'
		}, {
			label : '关联案件号',
			map : 'otherCaseCode',
			width : '10%'
		}, {
			label : '状态',
			map : 'statusName',
			width : '10%'
		}, {
			label : '操作',
			map : 'operation',
			width : '10%',
			cellTemplate:'<a  ng:bind="data.operation" '+
	 		'ng-click="operation(data)"></a>'}];
		
		$scope.operation = function(data){
            $state.go('problemDetailView.detail',{problemCode:data.problemCode,problemStatus:data.problemStatus});
		}
		
		var limit = 20;
		/**
		 * 分页监控
		 */
		$scope.$on('pageTool.skipPage',function(e,v){
             $scope.params.page = v;
             $scope.params.pageSize = limit;
             $scope.onSubmit(true);
         });
		
		
		$scope.onReset = function(){
				$scope.params.problemCode=null;
	        	$scope.params.orgName=null;
                $scope.params.hearDate={start:null,end:null};
                $scope.params.sourceType=null;
                $scope.params.doctorName=null;
                $scope.params.jobLicense=null;
                $scope.params.sbmitDate={start:null,end:null};
                $scope.params.problemStatus=null;
	        };
	        
        $scope.params = {
                page:1,
                pageSize:limit
            };
        
        /**
	     * 
	     **/
	    $scope.onSubmit = function(resetPage){
	    	var fparam = $scope.params;
	    	if(resetPage == null || !resetPage){
	    		$scope.currentPage= 1;
	    		$scope.params.page = 1; 
	    	}
	    	if($scope.params.sbmitDate){
		    	var start = $scope.params.sbmitDate.start;
		    	var end = $scope.params.sbmitDate.end;
		    	fparam.start = start;
		    	fparam.end = end;
	    	}
            if($scope.params.hearDate){
                var hearDateStart = $scope.params.hearDate.start;
                var hearDateEnd = $scope.params.hearDate.end;
                fparam.hearDateStart = hearDateStart;
                fparam.hearDateEnd = hearDateEnd;
            }
	    	if(!angular.isUndefined(fparam.orgName) && fparam.orgName=='') { 
	    		fparam.orgName=null;
    		}          
	    	if(!angular.isUndefined(fparam.orgCode) && fparam.orgCode=='') { 
	    		fparam.orgCode=null;
    		}          
	    	if(!angular.isUndefined(fparam.doctorName) && fparam.doctorName=='') { 
	    		fparam.doctorName=null;
    		}        
	    	if(!angular.isUndefined(fparam.jobLicense) && fparam.jobLicense=='') { 
	    		fparam.jobLicense=null;
    		}        
	    	if(!angular.isUndefined(fparam.sourceType) && fparam.sourceType=='') { 
	    		fparam.sourceType=null;
    		}        
	    	if(!angular.isUndefined(fparam.problemCode) && fparam.problemCode=='') { 
	    		fparam.problemCode=null;
	    	} 
	    	CaseCommonService.loadProblemsList(fparam).success(function(response){
	    		if(response){
            		$scope.tableData = response.result;
        			$scope.totalCount = response.totals.total;
	    		}
	    	});
	    
	    }
	    
	    $scope.onSubmit();
	// end line	
	}]);
})();
